package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import com.sky.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user where openid = #{openId}")
    User getUserByOpenId(String openId);

    @Insert("insert into user(id,openid,name,phone,sex,id_number,avatar,create_time)values (#{id}," +
            "#{openid},#{name},#{phone},#{sex},#{idNumber},#{avatar},#{createTime})")
    void saveUser(User newUser);

    List<ShoppingCart> getShoppingCartsById(ShoppingCart shoppingCart);
    @Update("update shopping_cart set number = #{number} where id = #{id} ")
    void updateShoppingCart(ShoppingCart shoppingCart);

    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount) " +
            "values (#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{number}, #{amount})")
    void addShoppingCart(ShoppingCart shoppingCart);

    @Delete("delete from shopping_cart where user_id = #{currentId}")
    void cleanShoppingCart(Long currentId);

    @Select("select * from shopping_cart where user_id = #{currentId}")
    List<ShoppingCart> getshoppingCartList(Long currentId);
    @Delete("delete from shopping_cart where id = #{id}")
    void deleteShoppingCart(ShoppingCart shoppingCart);
}
